#ifndef TRANSFORMERCONTENTDISPATHCER_HPP_3
#define TRANSFORMERCONTENTDISPATHCER_HPP_3

#include "transContentDefine.h"
#include "transContentErrorCode.h"
#include "transContentSetting.hpp"
#include "transContentMemory.hpp"
#include "logger.hpp"

///////////////////////////////////////////////////
/// when dispatch, some message need not send to port, just change the client setting
//////////////////////////////////////////////////
class TransContentDispatcher{
	private:
		int mState;
		int fd_fifo_dataOut_w;
		int fd_fifo_regist_w;
		int fd_fifo_dataIn_r;
		int fd_fifo_dataIn_w;
		pthread_mutex_t mutex_dataIn;
		pthread_mutex_t mutex_dataOut;
		pthread_mutex_t mutex_regist;
		TransContentMemory* memInstance;
		static TransContentDispatcher* _instance;
		static int stackRunningFlag;
	public:
		static TransContentDispatcher* getInstance();
		static void releaseInstance();

		int getState();

		int sendDataDataToStack(const char* content, int length);
		int sendDataRegistToStack(const char* content, int length);

		void receiveDataFromStack();

		int isStackRunning();

	private:
		int openFifoRegist();
		int openFifoDataOut();
		int openFifoLocalFifo();	
		TransContentDispatcher();
		~TransContentDispatcher();

		static int checkStackIsReady();

		void mkdirp();
		void dumpPacket(const char* content, int len);
};
#endif //TRANSFORMERCONTENTDISPATHCER_HPP_3
